package com.hadoop.sxtmr;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class HotMapper extends Mapper<LongWritable, Text, KeyPair, Text>{
	
	public SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	public Calendar cal = Calendar.getInstance();
	@Override
	protected void map(LongWritable key, Text value, org.apache.hadoop.mapreduce.Mapper.Context context)
			throws IOException, InterruptedException {
		String line = value.toString();
		String str [] = line.split(" ");
		KeyPair kp = new KeyPair();
		if(str.length == 2){
			try {
				System.out.println(value);
				cal.setTime(sdf.parse(str[0]));
				kp.setYear(cal.get(1));
				kp.setHot(Integer.valueOf(str[1].replace("`C", "")));
			} catch (Exception e) {
				e.printStackTrace();
			}
			context.write(kp, value);
		}
	}

}
